package com.shujia.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

//工具类
public class MySQLTool {
    //构造方法私有化
    private MySQLTool() {
    }

    //读取配置文件信息，返回数据库的连接信息
    public static Connection getMysqlConnection() {
        Connection connection = null;
        try {
            //读取配置文件
            //创建配置文件对象
            Properties properties = new Properties();
            //加载本地的配置文件
            properties.load(new BufferedReader(new FileReader("redis/src/main/resources/mysqlinfo.properties")));
            String url = (String) properties.get("url");
            String username = (String) properties.get("username");
            String password = (String) properties.get("password");
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(url, username, password);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;

    }

}
